//
//  CustomerSwitchButton.m
//  JomooCloudApp
//
//  Created by chewyong on 2018/10/9.
//

#import "CustomerSwitchButton.h"
#import "Utils.h"

@implementation CustomerSwitchButton

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundView.clipsToBounds = YES;
    self.backgroundView.layer.cornerRadius = 18;
    self.backgroundView.layer.borderWidth = 1;
    self.backgroundView.layer.borderColor = [UIColor lightGrayColor].CGColor;

    self.selectIndex = 0;
}

- (IBAction)firstButtonAction:(id)sender {
    self.selectIndex = 0;
}
- (IBAction)secondButtonAction:(id)sender {
    self.selectIndex = 1;
}
- (IBAction)thirdButtonAction:(id)sender {
    self.selectIndex = 2;
}

- (void)setSelectIndex:(NSInteger)selectIndex {
    _selectIndex = selectIndex;

    self.firstButton.clipsToBounds = YES;
    self.firstButton.layer.cornerRadius = 18;
    self.firstButton.layer.borderWidth = 1;
    self.firstButton.layer.borderColor = [UIColor clearColor].CGColor;
    [self.firstButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    self.secondButton.clipsToBounds = YES;
    self.secondButton.layer.cornerRadius = 18;
    self.secondButton.layer.borderWidth = 1;
    self.secondButton.layer.borderColor = [UIColor clearColor].CGColor;
    [self.secondButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    self.thirdButton.clipsToBounds = YES;
    self.thirdButton.layer.cornerRadius = 18;
    self.thirdButton.layer.borderWidth = 1;
    self.thirdButton.layer.borderColor = [UIColor clearColor].CGColor;
    [self.thirdButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    if (_selectIndex == 0) {
        self.firstButton.layer.borderColor = [Utils colorWithHexString:@"#E6C8A0"].CGColor;
        [self.firstButton setTitleColor:[Utils colorWithHexString:@"#E6C8A0"] forState:UIControlStateNormal];
    } else if (_selectIndex == 1) {
        self.secondButton.layer.borderColor = [Utils colorWithHexString:@"#E6C8A0"].CGColor;
        [self.secondButton setTitleColor:[Utils colorWithHexString:@"#E6C8A0"] forState:UIControlStateNormal];
    } else {
        self.thirdButton.layer.borderColor = [Utils colorWithHexString:@"#E6C8A0"].CGColor;
        [self.thirdButton setTitleColor:[Utils colorWithHexString:@"#E6C8A0"] forState:UIControlStateNormal];
    }
    if ([_delegate respondsToSelector:@selector(selectButtonIndex:)]) {
        [_delegate selectButtonIndex:_selectIndex];
    }
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
